package com.tuanzi.loan.business.service.galaxycard.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.retry.RetryException;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.tuanzi.loan.core.aspect.Debug;

import com.tuanzi.loan.business.service.galaxycard.GalaxyCardDistributionStatService;
import com.tuanzi.loan.vo.request.galaxycard.DistributionStatSearchRequest;
import com.tuanzi.loan.vo.response.galaxycard.GalaxyCardDistributionStatSearchResponse;
import com.tuanzi.loan.business.repository.galaxycard.GalaxyCardDistributionStatRepository;
import com.tuanzi.loan.core.vo.PageSearcher;
import org.springframework.data.domain.Page;

import java.util.Map;
import java.util.Objects;

/**
 * 分销统计 ServiceImplement
 * @author JinRuiyang 2018/3/2 10:29:34
 */
@Debug
@Service
@Transactional
@Retryable(value = { RetryException.class })
public class GalaxyCardDistributionStatServiceImpl implements GalaxyCardDistributionStatService {

    @Autowired
    private GalaxyCardDistributionStatRepository galaxyCardDistributionStatRepository;


    @Override
    public Map<String, Integer> getProduct() {
        return galaxyCardDistributionStatRepository.getProduct();
    }

    @Override
    public Map<String, Integer> getChannel() {
        return galaxyCardDistributionStatRepository.getChannel();
    }

    @Override
    public Map<String, String> getPlatform() {
        return galaxyCardDistributionStatRepository.getPlatform();
    }

    /**
     * DistributionStat查询
     * @param pageSearcher 请求信息
     * @return 响应列表
     */
    public Page<GalaxyCardDistributionStatSearchResponse> list(PageSearcher<DistributionStatSearchRequest> pageSearcher) {
        if (Objects.isNull(pageSearcher))
            throw new NullPointerException("pageSearcher is null");
        if (Objects.isNull(pageSearcher.getSearchCondition()) || Objects.isNull(pageSearcher.getPageable()))
            throw new NullPointerException("distributionStatSearchRequest or pageable is null");
        return galaxyCardDistributionStatRepository.list(pageSearcher.getSearchCondition(),pageSearcher.getPageable());
    }
}